package com.newegg.nlp.util.corenlp.zh;

import com.newegg.nlp.util.corenlp.Filter;
import com.newegg.nlp.util.corenlp.Keyword;
import com.newegg.nlp.util.corenlp.Result;
import com.newegg.nlp.util.corenlp.TagHelp;

import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphEdge;
import edu.stanford.nlp.simple.Sentence;
import edu.stanford.nlp.trees.GrammaticalRelation;

public class Filter_dep implements Filter{

	@Override
	public Result filter(SemanticGraphEdge graphEdge, SemanticGraph graph, Sentence sentence) {
		Result result = new Result();
		if("dep".equals(graphEdge.getRelation().getShortName())) { //依赖关系
			String advmod_str = "";
			IndexedWord advmod = graph.getChildWithReln(graphEdge.getSource(), GrammaticalRelation.valueOf("advmod"));
			if(advmod != null) {
				advmod_str = advmod.value();
			}
			IndexedWord obj = graph.getChildWithReln(graphEdge.getTarget(), GrammaticalRelation.valueOf("obj"));
			if(obj != null && TagHelp.isNN(obj.tag())) {
				result.addKeyword(new Keyword(advmod_str + graphEdge.getSource().value() + graphEdge.getTarget().value() + obj.value(), advmod_str + graphEdge.getSource().value(), obj.value()));
			}
		 }
		return result;
	}

}
